package principle.segregation;

/**
 * 接口隔离原则：只继承最小的接口
 * @author shkstart
 * @create ${year}-${month}-${day}-${time}
 */
public class segregation1 {
    public static void main(String[] args) {
        A a = new A();
        //通过接口去依赖(使用)b
        a.depend1(new B());
        a.depend2(new B());
        a.depend3(new B());
        C c = new C();
        c.depend1(new D());
        c.depend4(new D());
        c.depend5(new D());
    }
}
//接口
interface interface1{
    public void a();
}
interface interface2{
    public void b();
    public void c();
}
interface interface3{
    public void d();
    public void e();
}
class B implements interface1,interface2{
    @Override
    public void a() {
        System.out.println("b:a");
    }

    @Override
    public void b() {
        System.out.println("b:b");
    }

    @Override
    public void c() {
        System.out.println("b:c");
    }
}
class D implements interface1,interface3{
    @Override
    public void a() {
        System.out.println("d:a");
    }

    @Override
    public void d() {
        System.out.println("d:d");
    }

    @Override
    public void e() {
        System.out.println("d:e");
    }
}
class A {//通过interface1,2接口依赖b
    public void depend1(interface1 i){
        i.a();
    }
    public void depend2(interface2 i){
        i.b();
    }
    public void depend3(interface2 i){
        i.c();
    }
}
class C {//通过接口interface1,3依赖d
    public void depend1(interface1 i){
        i.a();
    }
    public void depend4(interface3 i){
        i.d();
    }
    public void depend5(interface3 i){
        i.e();
    }
}